package com.chunmeng.controller;

import com.chunmeng.pojo.JcbPojo;
import com.chunmeng.service.JcbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author yd
 * @version 1.0
 * @date 2020/3/6 0006 黄啟军
 */
@Controller
public class JcbController {
    private static Integer rem;
    @Autowired
    JcbService jcbService;
    /**查询全部*/
    @RequestMapping("/findAll")
     public String findAll(Model model){
         List<JcbPojo> all = jcbService.findAll();
         model.addAttribute("list",all);
         return "succeed";
     }
    /**来到添加页面*/
    @RequestMapping("/jcb")
    public String jcb(){
        return "jcb_add";
    }
    /**执行添加*/
    @RequestMapping("/add")
    public String add(Integer id,  String month, String jcbName, String bank, Double quota,
                      Double bmikece, Double used, String billingDate, String dueDate, String isAlso,
                      Double caffe, String genre, Double interest, String account, String remark){
        jcbService.insert(new JcbPojo(id,new Date(),month,jcbName,bank,quota,bmikece,used,billingDate,dueDate,isAlso,caffe,genre,interest,account,remark));
        return "succeed";
    }
    /**来到更新页面*/
    @RequestMapping("/update")
    public String update(Integer id,Model model){
        JcbPojo pojo = jcbService.selectByPrimaryKey(id);
        model.addAttribute("list",pojo);
        model.addAttribute("update",id);
        return "jcb_update";
    }
    /**执行更新操作*/
    @RequestMapping("/updateJcb")
    public String updateJcb(Integer id,  String month, String jcbName, String bank, Double quota,
                            Double bmikece, Double used, String billingDate, String dueDate, String isAlso,
                            Double caffe, String genre, Double interest, String account, String remark){
        jcbService.updateJcb(new JcbPojo(id,new Date(),month,jcbName,bank,quota,bmikece,used,billingDate,dueDate,isAlso,caffe,genre,interest,account,remark));
        return "succeed";
    }
    /**来到删除页面*/
    @RequestMapping("/delete")
    public String delete(Integer id,Model model){
        rem=id;
        return "jcb_delete";
    }
    /**删除取消*/
    @RequestMapping("/returnTest")
    public String returnTest(){
        return "succeed";
    }
    /**执行删除*/
    @RequestMapping("/remove")
    public String remove(){
        jcbService.remove(rem);
        return "succeed";
    }
}
